package com.highspeed.bdk.controller.physical;

import com.bianmaba.spring.data.jpa.domain.Result;
import com.bianmaba.spring.mvc.method.support.annotations.JSON;
import com.highspeed.bdk.bean.entity.physical.PhysicalLink;
import com.highspeed.bdk.controller.base.BdkCrudController;
import com.highspeed.bdk.service.base.IBdkBaseService;
import com.highspeed.bdk.service.physical.IPhysicalLinkService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = {"physical_link"}, method = RequestMethod.POST)
@Api(tags = "物理链路")
public class PhysicalLinkController extends BdkCrudController<PhysicalLink, Integer> {

    @Autowired()
    private IPhysicalLinkService physicalLinkService;

    @Override
    protected IBdkBaseService getService() {
        return this.physicalLinkService;
    }

    @ApiOperation(value = "保存物理链路列表", notes = "参数为JSON数据;<br/>" +
            "链路配置中中必须包含：leftCpu.id和rightCpu.id属性，不然不会与相关CPU关联（已经关联的也会断掉）;<br/>")

    @JSON(excludeProperties = {"data.*\\.board", "data.*\\.physicalTopology","data.*\\.foldPoints","data.*\\.leftLinks","data.*\\.rightLinks"})
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @Override
    public Result save(@RequestBody @ApiParam(name = "entity") PhysicalLink entity) {
        return super.save(entity);
    }

    @ApiOperation(value = "保存物理链路列表", notes = "参数为JSON数据;<br/>" +
            "每一个链路配置中中必须包含：leftCpu.id和rightCpu.id属性，不然不会与相关CPU关联（已经关联的则会断掉）;<br/>")

    @JSON(excludeProperties = {"data.*\\.board", "data.*\\.physicalTopology","data.*\\.foldPoints","data.*\\.leftLinks","data.*\\.rightLinks"})
    @RequestMapping(value = "/saves", method = RequestMethod.POST)
    @Override
    public Result save(@RequestBody @ApiParam(name = "entity") List<PhysicalLink> entity) {
        return super.save(entity);
    }


    @JSON(excludeProperties = {"data.*\\.board", "data.*\\.physicalTopology","data.*\\.foldPoints","data.*\\.leftLinks","data.*\\.rightLinks"})
    @ApiOperation(value = "查询指定cpu的所有物理链路列表")
    @ApiImplicitParam(name = "id", value = "cpuId", dataType = "int", paramType = "query")
    @RequestMapping({"/find_by_cpu_id"})
    public Result findByCpuId(Integer id) {
        List<PhysicalLink> list = physicalLinkService.findByCpuId(id);
        return new Result(true, null, list);
    }

    @JSON(excludeProperties = {"data.*\\.board", "data.*\\.physicalTopology","data.*\\.foldPoints","data.*\\.leftLinks","data.*\\.rightLinks"})
    @ApiOperation(value = "查询指定物理拓扑的所有链路列表")
    @ApiImplicitParam(name = "id", value = "cpu id", dataType = "int", paramType = "query")
    @RequestMapping({"/find_by_physical_topology_id"})
    public Result findByPhysicalTopologyId(Integer id) {
        List<PhysicalLink> list = physicalLinkService.findByPhysicalTopologyId(id);
        return new Result(true, null, list);
    }


    @JSON(excludeProperties = {"data.*\\.board", "data.*\\.physicalTopology","data.*\\.foldPoints","data.*\\.leftLinks","data.*\\.rightLinks"})
    @ApiOperation(value = "根据左右两个CPU ID查询物理链路")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leftCpuId", value = "左CPU id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "rightCpuId", value = "右Cpu id", dataType = "int", paramType = "query")}
    )
    @RequestMapping({"/find_by_two_cpu_id"})
    public Result findByTwoCpuId(Integer leftCpuId, Integer rightCpuId) {
        PhysicalLink physicalLink = physicalLinkService.findByTwoCpuId(leftCpuId, rightCpuId);
        return new Result(true, null, physicalLink);
    }


    @JSON(excludeProperties = {"data.*\\.board", "data.*\\.physicalTopology","data.*\\.foldPoints","data.*\\.leftLinks","data.*\\.rightLinks"})
    @ApiOperation(value = "根据左右两个CPU ID查询物理链路")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leftCpuId", value = "左CPU id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "rightCpuId", value = "右Cpu id", dataType = "int", paramType = "query")}
    )
    @RequestMapping({"/find_all_by_two_cpu_id"})
    public Result findAllByTwoCpuId(Integer leftCpuId, Integer rightCpuId) {
        List<PhysicalLink> list = physicalLinkService.findAllByTwoCpuId(leftCpuId, rightCpuId);
        return new Result(true, null, list);
    }
}
